package com.wsm.common.config;

import com.wsm.common.filter.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author wangshimin
 * @description 所有/files/路径 替换为存储地址路径
 */
@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
	@Autowired
	FilePathConfig filePathConfig;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/files/**").addResourceLocations("file:///" + filePathConfig.getUploadPath());
	}

	//添加拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//注册拦截器 拦截规则
		//多个拦截器时 以此添加 执行顺序按添加顺序
		registry.addInterceptor(new UserInterceptor()).addPathPatterns("/**");
	}

}